# -*- encoding=utf8 -*-

__author__ = "code哥"

from enum import Enum


class APPMode(Enum):
    USB = 1
    WIFI = 2


class Singleton(object):
    def __init__(self, cls):
        self._cls = cls
        self._instance = {}

    def __call__(self):
        if self._cls not in self._instance:
            self._instance[self._cls] = self._cls()
        return self._instance[self._cls]


@Singleton
class GlobalMap(object):
    map = {}

    def set_value(self, name, value):
        self.map[name] = value

    def get_value(self, name, def_value=None):
        try:
            return self.map[name]
        except KeyError:
            return def_value

    def get_global_dic(self):
        return self.map


# 当前模式USB WIFI
global_var_mode = APPMode.WIFI
# 当前运行环境
APP_DEV = False
